﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using OnlineAuction.DataAccess;
using OnlineAuction.Entity;

namespace OnlineAuction.Business
{
    public class UserBO
    {
        public List<UserDTO> ViewUser(string name)
        {
            //Get all users
            UserDA da = new UserDA();
            List<UserDTO> list = new List<UserDTO>();
            DataSet ds = da.ViewUser(name);
            //Convert DataRow to List items
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                list.Add(new UserDTO(row["UserName"].ToString(), row["UserFullName"].ToString(),
                    row["UserPhoneNumber"].ToString(), row["UserEmail"].ToString(),
                    row["UserIdentityCard"].ToString(), row["VirtualMoney"].ToString(),
                    row["UserState"].ToString()));
            }
            return list;
        }
        public UserDTO GetUser(string username)
        {
            //Get all users
            UserDA da = new UserDA();
            DataRow row = da.ViewUser(username).Tables[0].Rows[0];

            //Convert DataRow to item
            return new UserDTO(row["UserName"].ToString(), row["UserFullName"].ToString(), row["UserGender"].ToString(),
                row["UserPhoneNumber"].ToString(), row["UserAddress"].ToString(), row["UserEmail"].ToString(),
                row["UserIdentityCard"].ToString(), row["VirtualMoney"].ToString(), row["UserPassword"].ToString());

        }
        public bool CheckUserPassword(string UserName, string UserPassword)
        {
            UserDA da = new UserDA();
            return da.CheckUserPassword(UserName, UserPassword);
        }
        public bool ChangePassword(string UserName, string UserPassword)
        {
            UserDA da = new UserDA();
            return da.ChangePassword(UserName, UserPassword);
        }
        public bool DeleteUser(string UserName)
        {
            //delete user
            UserDA da = new UserDA();
            return da.DeleteUsers(UserName);
        }

        public bool BanUser(string UserName)
        {
            //delete user
            UserDA da = new UserDA();
            return da.BanUsers(UserName);
        }

        public bool ActiveUser(string UserName)
        {
            //delete user
            UserDA da = new UserDA();
            return da.ActiveUsers(UserName);
        }

        public bool AddUsers(UserDTO u)
        {
            //add user
            UserDA da = new UserDA();
            return da.AddUsers(u);
        }
        
        public bool UpdateProfile(UserDTO u)
        {
            //Update Profile
            UserDA da = new UserDA();
            return da.UpdateProfile(u);
        }
    }
}
